/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sump;

import java.awt.Graphics2D;
import java.awt.Image;

/**
 *
 * @author Diegolas
 */
public class Marissa extends Jugador{

    public Marissa() {
        velX = VariableList.vXJudador;
        velY = 0;
        colision.setFrame(100, 0, 30, 95);
        estado = "normal";
        posSprite = 0;
        Image normal[] = new Image[10];
        normal[0] = CargadorImagenes.get().cargar("ma_norm.png");
        sprites.put("normal", normal);
    }

    
    @Override
    public void actualizar(double dt, boolean[] teclas, Tile[][] mapeado) {
        
        double x1 = 0;
        double y1 = 0; 
        //abajo
        y1 = colision.getY() + ((dt)*velY)/1000;
        if (!estado.equals("saltando") && mapeado[(int)(y1+colision.getHeight())/50][(int)(colision.getX())/50]==null &&
                mapeado[(int)(y1+colision.getHeight())/50][(int)(colision.getX()+colision.getWidth())/50]==null)
        {
            setY(y1);
            lugar = "aire";
            if (velY<VariableList.vYJudador)
                velY +=60;
        }
        else if (!estado.equals("saltando"))
        {
            setY((int)((int)(y1+colision.getHeight())/50)*50-colision.getHeight()-1);
            lugar = "tierra";
            velY = 0;
        }
        
        y1 = colision.getY() - ((dt)*velY)/1000;
        if (lugar.equals("tierra") && teclas[Juego.B_ESPA])
        {
            estado = "saltando";
            lugar = "aire";
            velY = VariableList.vYJudador;
        }
        if (estado.equals("saltando"))
        {
            tiempoSaltando += dt;
            if (velY >= 0 &&(mapeado[(int)(y1)/50][(int)(colision.getX())/50]==null &&
                mapeado[(int)(y1)/50][(int)(colision.getX()+colision.getWidth())/50]==null))
            {
                setY(y1);
                velY -= 50;
            }
            else
            {
                estado = "caida";
                velY = 0;
                tiempoSaltando = 0;
            }
        }
        
        x1 = colision.getX()+((dt)*this.velX)/1000;
        if (teclas[Juego.DERECHA] && mapeado[(int)colision.getY()/50][(int)(x1+colision.getWidth())/50] == null &&
                mapeado[(int)(colision.getY()+colision.getHeight())/50][(int)(x1+colision.getWidth())/50] == null)
        {
            setX(x1);
        }
        else if (teclas[Juego.DERECHA])
        {
            setX((int)((int)(x1+colision.getWidth())/50)*50-colision.getWidth()-1);
        }
        
        x1 = colision.getX() -((dt)*this.velX)/1000;
        if (teclas[Juego.IZQUIERDA]&& mapeado[(int)colision.getY()/50][(int)(x1)/50] == null &&
                mapeado[(int)(colision.getY()+colision.getHeight())/50][(int)(x1)/50] == null)
        {
            setX(x1);
        }
        else if (teclas[Juego.IZQUIERDA])
        {
            setX((int)((int)(x1+50)/50)*50+1);
        }
        
    }

    @Override
    public void pintar(Graphics2D g2D) {
        g2D.drawImage(sprites.get("normal")[posSprite], xImg, yImg, null);
    }
    
    @Override
    public void setX(double x) {
        colision.setFrame(x, colision.getY(), colision.getWidth(), colision.getHeight());
        xImg = (int)x -17; 
        
    }

    @Override
    public void setY(double y) {
        colision.setFrame(colision.getX(),y , colision.getWidth(), colision.getHeight());
        yImg = (int)y -32; 
    }
}
